package pl.edu.uj.tcs.blef.protocol;

import java.io.PrintWriter;
import java.net.Socket;
import java.util.Vector;

import pl.edu.uj.tcs.blef.server.GlobalSettings;

public class ShowTablesRequestHandler implements RequestHandler {

	@Override
	public void handle(Request request, Socket socket) {
		Vector<String> tables = GlobalSettings._MAIN_SERVER_.getTables();
		StringBuilder sb = new StringBuilder();
		sb.append("OK /show-tables" + '\n');
		sb.append("TABLES: " + tables.size() + '\n');
		for(String s: tables){
			sb.append(s + '\n');
		}
		
		try {
			
			PrintWriter outputStream = new PrintWriter(socket.getOutputStream());
			outputStream.write(sb.toString());
			outputStream.flush();
			
		} catch(Exception e){ }
	}
}
